package run

import (
	"container/ring"
	"go-redis/utils"
)

var RDBChan = make(chan string)

type ClusterNode struct {
	DB             *Database
	Addr           string
	ReplBackBuffer ring.Ring
	ReplBuffer     map[string][]string
}

func (c *ClusterNode) Get(k string) interface{} {
	return c.DB.Get(k)
}

func (c *ClusterNode) Set(k string, v interface{}) bool {
	return c.DB.Set(k, v)
}

func (c *ClusterNode) Sync() {
	slaveId, _ := utils.GenerateRandomString(8)
	c.SlaveCopy(slaveId)
}

//func (c *ClusterNode) SendRDB() {
//	for {
//		var clientID string
//		select {
//		case clientID = <-RDBChan:
//
//		}
//	}
//}

//func (c *ClusterNode) Del(k string)  {
//	return c.
//}

func (c *ClusterNode) SlaveCopy(clientID string) {
	c.ReplBuffer[clientID] = make([]string, 10)
	go func() {
		c.DB.SaveRDB()
		RDBChan <- clientID
	}()
}
